import api from '../functions/request';

const formModule = {
    state: {
        codeTypesAll: {},
        pattern: []
    },
    mutations: {
        // 设置codeTypes
        SET_CODETYPES_All(state, value) {
            state.codeTypesAll = value;
        },
        // 设置正则
        SET_PATTERN(state, value) {
            state.pattern = value;
        }
    },
    getters: {
        codeTypesAll: state => state.codeTypesAll,
        pattern: state => state.pattern
    },
    actions: {
        // 设置codeTypes
        SET_CODETYPES_All({commit}, value) {
            let params = {
                codeTypes: value.codeTypes,
                codeTypeFilters: value.codeTypeFilters
            };
            api.commonPost('/form/doInit', params).then(res => {
                if (res.status == '0') {
                    commit('SET_CODETYPES_All', res.data && res.data.codeTypes);
                }
            })
        },
        // 设置正则
        SET_PATTERN({commit}, value) {
            let params = {
                regularList: value
            };
            api.commonPost('/regular/list', params).then(res => {
                if (res.status == '0') {
                    commit('SET_PATTERN', res.data || []);
                }
            });
        }
    }
};

export default formModule